import request from '@/utils/request'


// 查询出库申请表-条件查询
export function listOutSto(query) {
  const condition = {
    page:query.pageNum,
    count:query.pageSize,
    search:{
      outStoId:query.outStoId,
      outStoState: query.outStoState,
    }
  }
  return request({
    url: '/reverse/outsto/query',
    method: 'post',
    headers: {
      'Content-Type': 'application/json'
    },
    data:  JSON.stringify(condition)
  })
}

// 查询获取信息
export function getData() {
  return request({
    url: '/reverse/outsto',
    method: 'get'
  })
}

//查询详情，修改状态
export function getOutSto(outstoId) {
  return request({
    url: '/reverse/outsto/'+outstoId,
    method: 'get'
  })
}

//修改审批状态
export function updateOutSto(query,users,warehouses) {
   // 初始化userId和warehouseId
   let userId = null;
   let warehouseId = null;
 
   // 遍历用户数组，找到匹配的outStoActor
   users.forEach(user => {
     if (user.userName === query.outStoActor) {
       userId = user.userId; // 假设用户对象中有一个id属性
     }
   });
 
   // 遍历仓库数组，找到匹配的outStoWarehouse
   warehouses.forEach(warehouse => {
     if (warehouse.warehouseName === query.outStoWarehouse) {
       warehouseId = warehouse.warehouseId; // 假设仓库对象中有一个id属性
     }
   });
  const condition = {
    outStoId:query.outStoId,
    stoId:query.stoId,
    outStoState:query.outStoState,
    outStoWarehouse:query.outStoWarehouse,
    outStoActor:query.outStoActor,
    saleOutinventory:query.saleOutinventory,
    userId:userId,
    warehouseId:warehouseId
  }
  return request({
    url: '/reverse/outsto/update',
    method: 'post',
    headers: {
      'Content-Type': 'application/json'
    },
    data:  JSON.stringify(condition)
  })
}

